<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CMS首页</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/resource/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/resource/js/bootstrap.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath }/resource/css/bootstrap.css">
<link rel="stylesheet" href="${pageContext.request.contextPath }/resource/css/index.css">
</head>
<body>
	<!-- 定义一个大的模块 -->
	<div class="container">
		<!-- 图片(头) -->
		<div>
			<a href="${pageContext.request.contextPath }/"> <img alt="" src="${pageContext.request.contextPath }/resource/pic/logo-admin.jpg"
				height="50" width="100"></a>
			<hr>
		</div>

		<!-- 输入框 -->
		<div class="row">
			<div class="col-md-6">
				<form action="" method="post" id="loginForm">
					<div class="form-group">
						<label for="username">用户名：</label> <input name="username"
							class="form-control" id="username" />
					</div>
					<div class="form-group">
						<label for="password">密码：</label> <input name="password"
							class="form-control" id="password" />
					</div>
					<div class="form-group">
						<input type="reset" onclick="toRegister()" value="注册"
							class="btn btn-primary"> <input type="button"
							onclick="login()" value="登录" class="btn btn-primary">
						</button>
					</div>
				</form>
				<!-- 错误提示信息 -->
				<span id="errorMsg" style="color: red"></span>
			</div>
			<!-- 加图片，美化页面；/resource/pic/bg-reg.jpg  -->
			<div class="col-md-6">
				<img alt="" src="${pageContext.request.contextPath }/resource/pic/back-ground.png" height="300">
			</div>
		</div>
	</div>

</body>
<script type="text/javascript">
	
//登录操作
function login(){
      // 使用ajax进行登录操作
      $.post(
           "${pageContext.request.contextPath }/user/login",
           $("#loginForm").serialize(),
           function(result) {
                 if(result){
                      // 登录成功
                      location="${pageContext.request.contextPath }/index";
                 }else{
                      // 登录失败  js validate
                      $("#errorMsg").html("用户名或密码错误！");
                 }
                 
           }
      )
}

// 跳转到注册页面
function toRegister(){
      location = "toRegister"
}
	
	
</script>

</html>